package com.da.lon.wang.xlg.view;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.da.lon.wang.xlg.R;
import com.da.lon.wang.xlg.bean.DetailBean;

public class QuestionPopupWindow extends PopupWindow {

    private View mMenuView;
    private DetailBean bean = new DetailBean();
    private Context mContext;

    private TextView priceView, detailView;
    private ImageView priceImageView, closeImageView;

    public QuestionPopupWindow(Context context, DetailBean bean2) {
        // TODO Auto-generated constructor stub
        super(context);
        this.mContext = context;
        this.bean = bean2;

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mMenuView = inflater.inflate(R.layout.ouka_question_popupwindow, null);

        // 设置SelectPicPopupWindow的View
        this.setContentView(mMenuView);
        // 设置SelectPicPopupWindow弹出窗体的宽
        this.setWidth(LayoutParams.FILL_PARENT);
        // 设置SelectPicPopupWindow弹出窗体的高
        this.setHeight(LayoutParams.WRAP_CONTENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置SelectPicPopupWindow弹出窗体动画效果
        this.setAnimationStyle(R.style.AnimBottom);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
        // mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
        mMenuView.setOnTouchListener(new OnTouchListener() {

            public boolean onTouch(View v, MotionEvent event) {

                int height = mMenuView.findViewById(R.id.question_layout)
                        .getTop();
                int y = (int) event.getY();
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    if (y < height) {
                        dismiss();
                    }
                }
                return true;
            }
        });

        priceView = (TextView) mMenuView.findViewById(R.id.question_price);
        detailView = (TextView) mMenuView.findViewById(R.id.question_detail);
        priceImageView = (ImageView) mMenuView.findViewById(R.id.question_img);
        closeImageView = (ImageView) mMenuView
                .findViewById(R.id.question_close);

        if (bean.getRateprice() <= 50) {
            priceView.setText("￥" + bean.getRateprice());
            priceView.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
            priceImageView.setVisibility(View.VISIBLE);
        } else {
            priceView.setText("￥" + bean.getRateprice());
            priceImageView.setVisibility(View.GONE);
        }

        detailView
                .setText("本商品适用税率为"
                        + bean.getTaxrate()
                        + "%。依据《中华人民共和国进境归类表》的税率，以商品实际销售价格作为征税基数参照行邮税税率征收税款，"
                        + "应征税额在50元（含50元）以下的，海关予以免征。参照《海关总署公告2010年第43号》要求，个人自用单笔订单限制为1000元（单次购买单件商品超1000除外）。"
                        + "若您的订单总额超过1000元，欧咖建议您分多次购买。");

        closeImageView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                dismiss();
            }
        });
    }

}
